(function () {

    function findAndReplace(searchText, replacement, searchNode) {
        if (!searchText || typeof replacement === 'undefined') {
            // Throw error here if you want...
            return;
        }
        var regex = typeof searchText === 'string' ? new RegExp(searchText, 'g') : searchText,
            childNodes = (searchNode || document.body).childNodes,
            cnLength = childNodes.length;
        excludes = 'html,style,link,meta,script,object,iframe';
        while (cnLength--) {
            var currentNode = childNodes[cnLength];
            if (currentNode.nodeType === 1 && (',' + excludes + ',').indexOf(',' + currentNode.nodeName.toLowerCase() + ',') === -1) {
                arguments.callee(searchText, replacement, currentNode);
            }
            if (currentNode.nodeType !== 3 || !regex.test(currentNode.data)) {
                continue;
            }
            var parent = currentNode.parentNode,
                frag = (function () {
                    var html = currentNode.data.replace(regex, replacement),
                        wrap = document.createElement('div'),
                        frag = document.createDocumentFragment();
                    wrap.innerHTML = html;
                    while (wrap.firstChild) {
                        frag.appendChild(wrap.firstChild);
                    }
                    return frag;
                })();
            parent.insertBefore(frag, currentNode);
            parent.removeChild(currentNode);
        }
    }

    var css = ".nav-bar {width: 50%;}";
    if (typeof addStyle != "undefined") {
        addStyle(css);
    } else {
        var node = document.createElement("style");
        node.type = "text/css";
        node.appendChild(document.createTextNode(css));
        var heads = document.getElementsByTagName("head");
        if (heads.length > 0) {
            heads[0].appendChild(node);
        } else {
            // no head yet, stick it whereever
            document.documentElement.appendChild(node);
        }
    }

    function translate() {
        var ts = {
            "全部文件": "All Files",
            "保险箱": "Save",
            "我的分享": "Sharing",
            "网盘": "Drive",
            "相册": "Album",
            "回收站": "Recycle",
            "免费扩容": "Free space",
            "PC客户端": "PC client",
            "更多": "More",
            "返回": "Return",
            "上传": "Upload",
            "新建文件夹": "New Folder",
            "云收藏": "My Cloud",
            "下载": "Download",
            "删除": "Delete",
            "分享": "Sharing",
            "已经抽奖": "Already",
            "帐号安全中心": "My Account",
            "云盘消息": "Message",
            "云盘等级": "Level",
			"每日抽奖": "Daily Draw",
            "扩容记录": "Logs",
            "空间升级卡": "Upgrade",
            "邀请好友": "Referral",
            "意见反馈": "Feedback",
            "帮助中心": "Help",
            "退出云盘": "Logout",
			"加载文件列表中": "Load list files",
            "排序": "Sort",
            "名称": "Name",
            "重命名": "Rename",
            "移动": "Move",
            "转出文件Save": "Transfer",
            "文件时光机": "History",
            "离线Download": "Download",
            "转入文件Save": "Transfer",
        };
        for (var t in ts) {
            findAndReplace(t, ts[t]);
        };
        setTimeout(translate, 1000);
    };

    setTimeout(translate, 1000);

})();